Kotlin for Android App Development (Jakov Mestrovic's Library) by Peter Sommerhoff
Author:Peter Sommerhoff
Language: eng
Format: mobi, epub
Publisher: Addison-Wesley Professional
Published: 2019-10-14T16:00:00+00:00
runBlocking {
val deferred: Deferred<Int> = async { throw Exception("Failed...") }
try {
deferred.await() // Tries to get result of asynchronous call, throws exception
} catch (e: Exception) {
// Handle failure case here
}
}
You can also check the state of a Deferred directly using the properties isCompleted and isCompletedExceptionally. Be aware that the latter being false does not mean the operation completed successfully, it may instead still be active. In addition to these, there is also a deferred.invokeOnCompletion callback in which you may use deferred.getCompletionExceptionOrNull to get access to the thrown exception. In most cases, the approach in Listing 6.25 should suffice and is more readable.
Note
Notice the similar relations between launch/join and async/await. Both launch and async are used to start a new coroutine that performs work in parallel. With launch, you may wait for completion using join, whereas with async, you normally use await to retrieve the result.
While launch returns a Job, async returns a Deferred. However, Deferred implements the Job interface so you may use cancel and join on a Deferred as well, although this is less common.
Download
Kotlin for Android App Development (Jakov Mestrovic's Library) by Peter Sommerhoff.epub
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
How to Build Android Apps with Kotlin by Alex Forrester Eran Boudjnah Alexandru Dumbravan and Jomar Tigcal(2134)
Android Studio Arctic Fox Essentials - Kotlin Edition by Smyth Neil;(1988)
Learn SwiftUI for iOS 13 by Unknown(931)
Android Studio 4. 1 Development Essentials - Kotlin Edition by Smyth Neil;(671)
Windows 10: The Missing Manual by Pogue David(536)
Android Smartphone Photography For Dummies by Mark Hemmings(528)
iPad Application Development For Dummies by Neal Goldstein(460)
Kotlin And Android: Learn To Architect And Develop Android Apps In The Kotlin Programming Language: Android Development With Kotlin by Murdoch Reuben(457)
Android Phones for Dummies by Gookin Dan;(418)
Amazing Android Apps For Dummies by Begun Daniel A(415)
Apple Watch For Dummies by Unknown(405)
Mobile Photography by Scott La Counte(381)
Android Q&A: Android Questions & Answers by Exponential Mobile(365)
Android Q&A by Exponential Mobile(354)
Android for Absolute Beginners by Grant Allen(340)
Kotlin and Android Development featuring Jetpack by Michael Fazio(298)
iPad User Guide by Apple Inc(295)
Programming Kotlin: Enhance your skills for Android development using Kotlin by Aronowitz Alexander & lnc NLN(289)
Programming Kotlin: Enhance your skills for Android development using Kotlin by Alexander Aronowitz & NLN lnc(281)
